<?php
namespace View;
$phpself = $_SERVER['QUERY_STRING']; 
class NavigationView {

	public static function getEditUserLink($userId) {
		return self::getpostLink($userId) . "&edit";
	}
	
	private static $objID = "objID";
	private static $edit = "&edit";
	private static $page = "page";
	private static $register = "register";
	private static $newObj = "newobject";
	/**
	 * @return boolean
	 */
	public static function isViewingObj() {
		return isset($_GET[self::$objID]);
	}

	public static function isTryingToEdit() {
		return isset($_GET[self::$objID. self::$edit]);
	}
	
	public static function tryingToRegister(){
		return isset($_GET[self::$register]);
	}
	
	public static function addingNewPost() {
		return isset($_GET[self::$newObj]);
	}
	
	/**
	 * return String URL
	 */
	public static function getpostListLink() {
		return "?";
	}

	public static function getpostLink(\Model\Object $object) {
		return "?" . self::$objID . "=" . $object -> getId();
	}

	/**
	 * @return \Model\post selected post
	 */
	public static function getSelectedObject(\Model\ObjectHandler $objecthandler, \Model\Database $database) {
		if (isset($_GET[self::$objID])) {
			$urlId = $_GET[self::$objID];

			if ($urlId != "0" && intval($urlId) == 0) {
				throw new \Exception("getSelectedpost() URL called with wrong format");
			} else {
				$objID = intval($urlId);
				return $objecthandler -> getObjByID($objID, $database);
			}
		} else {
			throw new \Exception("getSelectedObject can only be called when we view a object");
		}
	}
}
